#include "../client/Connection.hpp"
#include <memory>

void handleMessage(micromq::Channel::ptr channel, const std::string& tag, 
    const micromq::BasicProperties* bp, const std::string& content)
{
    std::cout << "consumer: " << tag << " receive a message: " << content << std::endl;
    channel->ackMessage(bp->id());
}

int main(int argc, char* argv[])
{
    micromq::Connection::ptr conn = std::make_unique<micromq::Connection>("127.0.0.1", 9090);
    conn->connect();
    micromq::Channel::ptr channel = conn->openChannel();
    
    google::protobuf::Map<std::string, std::string> args;
    channel->declareExchange("exchange1", micromq::ExchangeType::TOPIC, true, false, args);
    channel->declareMagQueue("msgQueue1", true, false, false, args);
    channel->declareMagQueue("msgQueue2", true, false, false, args);
    
    channel->bind("exchange1", "msgQueue1", "news.game.EldenRing");
    channel->bind("exchange1", "msgQueue2", "news.music.#");
    
    channel->followMsgQueue("consumer1", argv[1], false, std::bind(&handleMessage, channel, 
        std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));

    while(true)
    {}

    conn->closeChannel(channel);

    return 0;
}